<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    var p = {
      firstName: 'A',
      lastName: 'B'
    }
    /*
    需求 
    给p添加一个新属性: fullName = firstName + '-' + lastName
    如果修改fullName firstName和lastName的值也会改变
    反之fullName的值会改变
    */
    Object.defineProperty(p, 'fullName', {
      get() {
        return firstName + '-' + lastName
      },
      set(value) {
        const names = value.split('-')
        this.firstName = names[0]
        this.lastName = names[1]
      }
    })
  </script>
</body>
</html>